package com.ellen.mac.chatdemo.adpter;

import android.content.Context;
import android.widget.SeekBar;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ellen.mac.chatdemo.R;
import com.ellen.mac.chatdemo.model.DataMP3Bean;
import com.ellen.mac.chatdemo.utils.LocalCacheUtils;
import com.ellen.mac.chatdemo.utils.PathUtils;
import com.ellen.mac.chatdemo.view.PlayButton;

import java.util.List;

/**
 * Created by j on 2017/12/14.
 */

public class NewVoiceAdapter extends BaseQuickAdapter<DataMP3Bean, BaseViewHolder> {
    private Context context;
    protected PlayButton playButton;
    public NewVoiceAdapter(int layoutResId, List data, Context context) {
        super(layoutResId, data);
        this.context = context;
    }
    @Override
    protected void convert(BaseViewHolder helper, DataMP3Bean item) {
        String path = PathUtils.getAudioCachePath(context,item.getObjectId()+".mp3");
        helper.setText(R.id.chat_item_audio_duration_view,item.getDuration()+"'");
        playButton = helper.getView(R.id.chat_item_audio_play_btn);
        SeekBar seekbar = helper.getView(R.id.seekbar_item);
        if(seekbar!=null){
            seekbar.setMax((int)item.getDuration());
            playButton.initSeekBar((SeekBar) helper.getView(R.id.seekbar_item),context);
        }

        LocalCacheUtils.downloadFileAsync(item.getUrl(), path);
        playButton.setPath(path);
    }
}


